package com.example.neusoft215gdh.androidpro_21.Activity;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.example.neusoft215gdh.androidpro_21.Adapter.ClubSearchAdapter;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubList;
import com.example.neusoft215gdh.androidpro_21.Listener.UserListenerr;
import com.example.neusoft215gdh.androidpro_21.Model.ClubModel;
import com.example.neusoft215gdh.androidpro_21.R;

import java.util.List;

public class SearchClubActivity extends Activity implements UserListenerr,View.OnClickListener{

    private ImageButton back_club;
    private View view = null;
    private ClubSearchAdapter adapter = null;
    List<ClubList> clubListsearch = null;
    private Button button_search;
    private EditText keywordView;
    private RecyclerView recycleviewclub;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_club);
        initRecyclerView(view);

        back_club = (ImageButton) findViewById(R.id.back_club);
        keywordView = (EditText) findViewById(R.id.textView_keyword);
        button_search = (Button) findViewById(R.id.button_search);
        button_search.setOnClickListener(this);
        back_club.setOnClickListener(this);

    }

    public  void initRecyclerView(View view){
        recycleviewclub=(RecyclerView) findViewById(R.id.recycleview_search);
        recycleviewclub.setLayoutManager(new LinearLayoutManager(this));
        recycleviewclub.setItemAnimator(new DefaultItemAnimator());
        adapter = new ClubSearchAdapter(this,clubListsearch);
    }

    @Override
    public void onResponse(Object beanobject) {
        recycleviewclub.setAdapter(new ClubSearchAdapter(getApplication(),(List<ClubList>)beanobject));
            adapter.getSearchClub(clubListsearch);
            adapter.notifyDataSetChanged();
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button_search:
                ClubModel clubModel=new ClubModel();
               final String club_name = keywordView.getText().toString();
               clubModel.getSearchClub(club_name,this);
                break;
            case R.id.back_club:
                finish();
                break;
        }
    }
}
